home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / idl / nsIXPConnect.idl < prev    next >
Text File  |  2006-05-08  |  29KB  |  659 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is Mozilla Communicator client code, released
  17.  * March 31, 1998.
  18.  *
  19.  * The Initial Developer of the Original Code is
  20.  * Netscape Communications Corporation.
  21.  * Portions created by the Initial Developer are Copyright (C) 1998
  22.  * the Initial Developer. All Rights Reserved.
  23.  *
  24.  * Contributor(s):
  25.  *   John Bandhauer <jband@netscape.com> (original author)
  26.  *   Nate Nielsen <nielsen@memberwebs.com> 
  27.  *
  28.  * Alternatively, the contents of this file may be used under the terms of
  29.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  30.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  31.  * in which case the provisions of the GPL or the LGPL are applicable instead
  32.  * of those above. If you wish to allow use of your version of this file only
  33.  * under the terms of either the GPL or the LGPL, and not to allow others to
  34.  * use your version of this file under the terms of the MPL, indicate your
  35.  * decision by deleting the provisions above and replace them with the notice
  36.  * and other provisions required by the GPL or the LGPL. If you do not delete
  37.  * the provisions above, a recipient may use your version of this file under
  38.  * the terms of any one of the MPL, the GPL or the LGPL.
  39.  *
  40.  * ***** END LICENSE BLOCK ***** */
  41.  
  42. /* The core XPConnect public interfaces. */
  43.  
  44. #include "nsISupports.idl"
  45. #include "nsIClassInfo.idl"
  46. #include "xpccomponents.idl"
  47. #include "xpcjsid.idl"
  48. #include "xpcexception.idl"
  49. #include "nsIInterfaceInfo.idl"
  50. #include "nsIInterfaceInfoManager.idl"
  51. #include "nsIExceptionService.idl"
  52. #include "nsIVariant.idl"
  53.  
  54. %{ C++
  55. #include "jspubtd.h"
  56. #include "xptinfo.h"
  57. %}
  58.  
  59. /***************************************************************************/
  60.  
  61. [ptr] native JSContextPtr(JSContext);
  62. [ptr] native JSObjectPtr(JSObject);
  63. [ptr] native JSValPtr(jsval);
  64.       native JSVal(jsval);
  65.       native JSID(jsid);
  66. [ptr] native voidPtrPtr(void*);
  67.  
  68. /***************************************************************************/
  69.  
  70. %{ C++
  71. /***************************************************************************/
  72. #define GENERATE_XPC_FAILURE(x) \
  73.             (NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCONNECT,x))
  74.  
  75. #define NS_ERROR_XPC_NOT_ENOUGH_ARGS                   GENERATE_XPC_FAILURE( 1)
  76. #define NS_ERROR_XPC_NEED_OUT_OBJECT                   GENERATE_XPC_FAILURE( 2)
  77. #define NS_ERROR_XPC_CANT_SET_OUT_VAL                  GENERATE_XPC_FAILURE( 3)
  78. #define NS_ERROR_XPC_NATIVE_RETURNED_FAILURE           GENERATE_XPC_FAILURE( 4)
  79. #define NS_ERROR_XPC_CANT_GET_INTERFACE_INFO           GENERATE_XPC_FAILURE( 5)
  80. #define NS_ERROR_XPC_CANT_GET_PARAM_IFACE_INFO         GENERATE_XPC_FAILURE( 6)
  81. #define NS_ERROR_XPC_CANT_GET_METHOD_INFO              GENERATE_XPC_FAILURE( 7)
  82. #define NS_ERROR_XPC_UNEXPECTED                        GENERATE_XPC_FAILURE( 8)
  83. #define NS_ERROR_XPC_BAD_CONVERT_JS                    GENERATE_XPC_FAILURE( 9)
  84. #define NS_ERROR_XPC_BAD_CONVERT_NATIVE                GENERATE_XPC_FAILURE(10)
  85. #define NS_ERROR_XPC_BAD_CONVERT_JS_NULL_REF           GENERATE_XPC_FAILURE(11)
  86. #define NS_ERROR_XPC_BAD_OP_ON_WN_PROTO                GENERATE_XPC_FAILURE(12)
  87. #define NS_ERROR_XPC_CANT_CONVERT_WN_TO_FUN            GENERATE_XPC_FAILURE(13)
  88. #define NS_ERROR_XPC_CANT_DEFINE_PROP_ON_WN            GENERATE_XPC_FAILURE(14)
  89. #define NS_ERROR_XPC_CANT_WATCH_WN_STATIC              GENERATE_XPC_FAILURE(15)
  90. #define NS_ERROR_XPC_CANT_EXPORT_WN_STATIC             GENERATE_XPC_FAILURE(16)
  91. #define NS_ERROR_XPC_SCRIPTABLE_CALL_FAILED            GENERATE_XPC_FAILURE(17)
  92. #define NS_ERROR_XPC_SCRIPTABLE_CTOR_FAILED            GENERATE_XPC_FAILURE(18)
  93. #define NS_ERROR_XPC_CANT_CALL_WO_SCRIPTABLE           GENERATE_XPC_FAILURE(19)
  94. #define NS_ERROR_XPC_CANT_CTOR_WO_SCRIPTABLE           GENERATE_XPC_FAILURE(20)
  95. #define NS_ERROR_XPC_CI_RETURNED_FAILURE               GENERATE_XPC_FAILURE(21)
  96. #define NS_ERROR_XPC_GS_RETURNED_FAILURE               GENERATE_XPC_FAILURE(22)
  97. #define NS_ERROR_XPC_BAD_CID                           GENERATE_XPC_FAILURE(23)
  98. #define NS_ERROR_XPC_BAD_IID                           GENERATE_XPC_FAILURE(24)
  99. #define NS_ERROR_XPC_CANT_CREATE_WN                    GENERATE_XPC_FAILURE(25)
  100. #define NS_ERROR_XPC_JS_THREW_EXCEPTION                GENERATE_XPC_FAILURE(26)
  101. #define NS_ERROR_XPC_JS_THREW_NATIVE_OBJECT            GENERATE_XPC_FAILURE(27)
  102. #define NS_ERROR_XPC_JS_THREW_JS_OBJECT                GENERATE_XPC_FAILURE(28)
  103. #define NS_ERROR_XPC_JS_THREW_NULL                     GENERATE_XPC_FAILURE(29)
  104. #define NS_ERROR_XPC_JS_THREW_STRING                   GENERATE_XPC_FAILURE(30)
  105. #define NS_ERROR_XPC_JS_THREW_NUMBER                   GENERATE_XPC_FAILURE(31)
  106. #define NS_ERROR_XPC_JAVASCRIPT_ERROR                  GENERATE_XPC_FAILURE(32)
  107. #define NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS     GENERATE_XPC_FAILURE(33)
  108. #define NS_ERROR_XPC_CANT_CONVERT_PRIMITIVE_TO_ARRAY   GENERATE_XPC_FAILURE(34)
  109. #define NS_ERROR_XPC_CANT_CONVERT_OBJECT_TO_ARRAY      GENERATE_XPC_FAILURE(35)
  110. #define NS_ERROR_XPC_NOT_ENOUGH_ELEMENTS_IN_ARRAY      GENERATE_XPC_FAILURE(36)
  111. #define NS_ERROR_XPC_CANT_GET_ARRAY_INFO               GENERATE_XPC_FAILURE(37)
  112. #define NS_ERROR_XPC_NOT_ENOUGH_CHARS_IN_STRING        GENERATE_XPC_FAILURE(38)
  113. #define NS_ERROR_XPC_SECURITY_MANAGER_VETO             GENERATE_XPC_FAILURE(39)
  114. #define NS_ERROR_XPC_INTERFACE_NOT_SCRIPTABLE          GENERATE_XPC_FAILURE(40)
  115. #define NS_ERROR_XPC_INTERFACE_NOT_FROM_NSISUPPORTS    GENERATE_XPC_FAILURE(41)
  116. #define NS_ERROR_XPC_CANT_GET_JSOBJECT_OF_DOM_OBJECT   GENERATE_XPC_FAILURE(42)
  117. #define NS_ERROR_XPC_CANT_SET_READ_ONLY_CONSTANT       GENERATE_XPC_FAILURE(43)
  118. #define NS_ERROR_XPC_CANT_SET_READ_ONLY_ATTRIBUTE      GENERATE_XPC_FAILURE(44)
  119. #define NS_ERROR_XPC_CANT_SET_READ_ONLY_METHOD         GENERATE_XPC_FAILURE(45)
  120. #define NS_ERROR_XPC_CANT_ADD_PROP_TO_WRAPPED_NATIVE   GENERATE_XPC_FAILURE(46)
  121. #define NS_ERROR_XPC_CALL_TO_SCRIPTABLE_FAILED         GENERATE_XPC_FAILURE(47)
  122. #define NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED    GENERATE_XPC_FAILURE(48)
  123. #define NS_ERROR_XPC_BAD_ID_STRING                     GENERATE_XPC_FAILURE(49)
  124. #define NS_ERROR_XPC_BAD_INITIALIZER_NAME              GENERATE_XPC_FAILURE(50)
  125. #define NS_ERROR_XPC_HAS_BEEN_SHUTDOWN                 GENERATE_XPC_FAILURE(51)
  126. #define NS_ERROR_XPC_CANT_MODIFY_PROP_ON_WN            GENERATE_XPC_FAILURE(52)
  127. #define NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL    GENERATE_XPC_FAILURE(53)
  128.  
  129. #ifdef XPC_IDISPATCH_SUPPORT
  130. // IDispatch support related errors
  131. #define NS_ERROR_XPC_COM_UNKNOWN                       GENERATE_XPC_FAILURE(54)
  132. #define NS_ERROR_XPC_COM_ERROR                         GENERATE_XPC_FAILURE(55)
  133. #define NS_ERROR_XPC_COM_INVALID_CLASS_ID              GENERATE_XPC_FAILURE(56)
  134. #define NS_ERROR_XPC_COM_CREATE_FAILED                 GENERATE_XPC_FAILURE(57)
  135. #define NS_ERROR_XPC_IDISPATCH_NOT_ENABLED             GENERATE_XPC_FAILURE(58)
  136. #endif
  137. // any new errors here should have an associated entry added in xpc.msg
  138. /***************************************************************************/
  139. %}
  140.  
  141. /***************************************************************************/
  142.  
  143. // forward declarations...
  144. interface nsIXPCScriptable;
  145. interface nsIXPConnect;
  146. interface nsIXPConnectWrappedNative;
  147. interface nsIInterfaceInfo;
  148. interface nsIXPCSecurityManager;
  149.  
  150. /***************************************************************************/
  151. [uuid(8916a320-d118-11d3-8f3a-0010a4e73d9a)]
  152. interface nsIXPConnectJSObjectHolder : nsISupports
  153. {
  154.     readonly attribute JSObjectPtr      JSObject;
  155. };
  156.  
  157. [uuid(215DBE02-94A7-11d2-BA58-00805F8A5DD7)]
  158. interface nsIXPConnectWrappedNative : nsIXPConnectJSObjectHolder
  159. {
  160.     /* attribute 'JSObject' inherited from nsIXPConnectJSObjectHolder */
  161.     readonly attribute nsISupports      Native;
  162.     readonly attribute JSObjectPtr      JSObjectPrototype;
  163.  
  164.     /**
  165.      * These are here as an aid to nsIXPCScriptable implementors
  166.      */
  167.  
  168.     readonly attribute nsIXPConnect XPConnect;
  169.     nsIInterfaceInfo FindInterfaceWithMember(in JSVal nameID);
  170.     nsIInterfaceInfo FindInterfaceWithName(in JSVal nameID);
  171.  
  172.     void debugDump(in short depth);
  173.  
  174.     void refreshPrototype();
  175.     /* 
  176.      * This returns a pointer into the instance and care should be taken
  177.      * to make sure the pointer is not kept past the life time of the
  178.      * object it points into.
  179.      */
  180.     voidPtrPtr GetSecurityInfoAddress();
  181.  
  182. %{C++
  183.     /**
  184.      * Faster access to the native object from C++.  Will never return null.
  185.      */
  186.     nsISupports* Native() const { return mIdentity; }
  187.  
  188. protected:
  189.     nsISupports *mIdentity;
  190. public:
  191. %}
  192. };
  193.  
  194. %{C++
  195. inline
  196. const nsQueryInterface
  197. do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative)
  198. {
  199.     return nsQueryInterface(aWrappedNative->Native());
  200. }
  201.  
  202. inline
  203. const nsQueryInterfaceWithError
  204. do_QueryWrappedNative(nsIXPConnectWrappedNative *aWrappedNative,
  205.                       nsresult *aError)
  206.  
  207. {
  208.     return nsQueryInterfaceWithError(aWrappedNative->Native(), aError);
  209. }
  210.  
  211. %}
  212.  
  213. [uuid(BED52030-BCA6-11d2-BA79-00805F8A5DD7)]
  214. interface nsIXPConnectWrappedJS : nsIXPConnectJSObjectHolder
  215. {
  216.     /* attribute 'JSObject' inherited from nsIXPConnectJSObjectHolder */
  217.     readonly attribute nsIInterfaceInfo InterfaceInfo;
  218.     readonly attribute nsIIDPtr         InterfaceIID;
  219.  
  220.     void debugDump(in short depth);
  221.  
  222.     void aggregatedQueryInterface(in nsIIDRef uuid,
  223.                                   [iid_is(uuid),retval] out nsQIResult result);
  224. };
  225.  
  226. /***************************************************************************/
  227.  
  228. /**
  229. * This is a somewhat special interface. It is available from the global
  230. * nsIXPConnect object when native methods have been called. It is only relevant
  231. * to the currently called native method on the given JSContext/thread. Holding
  232. * a reference past that time (or while other native methods are being called)
  233. * will not assure access to this data.
  234. */
  235.  
  236. [uuid(0FA68A60-8289-11d3-BB1A-00805F8A5DD7)]
  237. interface nsIXPCNativeCallContext : nsISupports
  238. {
  239.  
  240.     readonly attribute nsISupports                  Callee;
  241.     readonly attribute PRUint16                     CalleeMethodIndex;
  242.     readonly attribute nsIXPConnectWrappedNative    CalleeWrapper;
  243.     readonly attribute JSContextPtr                 JSContext;
  244.     readonly attribute PRUint32                     Argc;
  245.     readonly attribute JSValPtr                     ArgvPtr;
  246.     /**
  247.     * This may be NULL if the JS caller is ignoring the result of the call.
  248.     */
  249.     readonly attribute JSValPtr                     RetValPtr;
  250.     /**
  251.     * Set this if JS_SetPendingException has been called. Return NS_OK or
  252.     * else this will be ignored and the native method's nsresult will be
  253.     * converted into an exception and thrown into JS as is the normal case.
  254.     */
  255.     attribute PRBool                                ExceptionWasThrown;
  256.  
  257.     /**
  258.     * Set this to indicate that the callee has directly set the return value
  259.     * (using RetValPtr and the JSAPI). If set then xpconnect will not attempt
  260.     * to overwrite it with the converted retval from the C++ callee.
  261.     */
  262.     attribute PRBool                                ReturnValueWasSet;
  263.  
  264.     // Methods added since mozilla 0.6....
  265.  
  266.     readonly attribute nsIInterfaceInfo             CalleeInterface;
  267.     readonly attribute nsIClassInfo                 CalleeClassInfo;
  268. };
  269.  
  270. /***************************************************************************/
  271.  
  272. /**
  273.  * This is a sort of a placeholder interface. It is not intended to be
  274.  * implemented. It exists to give the nsIXPCSecurityManager an iid on
  275.  * which to gate a specific activity in XPConnect.
  276.  *
  277.  * That activity is...
  278.  *
  279.  * When JavaScript code uses a component that is itself implemeted in
  280.  * JavaScript then XPConnect will build a wrapper rather than directly
  281.  * expose the JSObject of the component. This allows components implemented
  282.  * in JavaScript to 'look' just like any other xpcom component (from the
  283.  * perspective of the JavaScript caller). This insulates the component from
  284.  * the caller and hides any properties or methods that are not part of the
  285.  * interface as declared in xpidl. Usually this is a good thing.
  286.  *
  287.  * However, in some cases it is useful to allow the JS caller access to the
  288.  * JS component's underlying implementation. In order to facilitate this
  289.  * XPConnect supports the 'wrappedJSObject' property. The caller code can do:
  290.  *
  291.  * // 'foo' is some xpcom component (that might be implemented in JS).
  292.  * try {
  293.  *   var bar = foo.wrappedJSObject;
  294.  *   if(bar) {
  295.  *      // bar is the underlying JSObject. Do stuff with it here.
  296.  *   }
  297.  * } catch(e) {
  298.  *   // security exception?
  299.  * }
  300.  *
  301.  * Recall that 'foo' above is an XPConnect wrapper, not the underlying JS
  302.  * object. The property get "foo.wrappedJSObject" will only succeed if three
  303.  * conditions are met:
  304.  *
  305.  * 1) 'foo' really is an XPConnect wrapper around a JSObject.
  306.  * 2) The underlying JSObject actually implements a "wrappedJSObject"
  307.  *    property that returns a JSObject. This is called by XPConnect. This
  308.  *    restriction allows wrapped objects to only allow access to the underlying
  309.  *    JSObject if they choose to do so. Ususally this just means that 'foo'
  310.  *    would have a property tht looks like:
  311.  *       this.wrappedJSObject = this.
  312.  * 3) The implemementation of nsIXPCSecurityManager (if installed) allows
  313.  *    a property get on the interface below. Although the JSObject need not
  314.  *    implement 'nsIXPCWrappedJSObjectGetter', XPConnect will ask the
  315.  *    security manager if it is OK for the caller to access the only method
  316.  *    in nsIXPCWrappedJSObjectGetter before allowing the activity. This fits
  317.  *    in with the security manager paradigm and makes control over accessing
  318.  *    the property on this interface the control factor for getting the
  319.  *    underlying wrapped JSObject of a JS component from JS code.
  320.  *
  321.  * Notes:
  322.  *
  323.  * a) If 'foo' above were the underlying JSObject and not a wrapper at all,
  324.  *    then this all just works and XPConnect is not part of the picture at all.
  325.  * b) One might ask why 'foo' should not just implement an interface through
  326.  *    which callers might get at the underlying object. There are three reasons:
  327.  *   i)   XPConnect would still have to do magic since JSObject is not a
  328.  *        scriptable type.
  329.  *   ii)  JS Components might use aggregation (like C++ objects) and have
  330.  *        different JSObjects for different interfaces 'within' an aggregate
  331.  *        object. But, using an additional interface only allows returning one
  332.  *        underlying JSObject. However, this allows for the possibility that
  333.  *        each of the aggregte JSObjects could return something different.
  334.  *        Note that one might do: this.wrappedJSObject = someOtherObject;
  335.  *   iii) Avoiding the explicit interface makes it easier for both the caller
  336.  *        and the component.
  337.  *
  338.  *  Anyway, some future implementation of nsIXPCSecurityManager might want
  339.  *  do special processing on 'nsIXPCSecurityManager::CanGetProperty' when
  340.  *  the interface id is that of nsIXPCWrappedJSObjectGetter.
  341.  */
  342.  
  343. [scriptable, uuid(254bb2e0-6439-11d4-8fe0-0010a4e73d9a)]
  344. interface nsIXPCWrappedJSObjectGetter : nsISupports
  345. {
  346.     readonly attribute nsISupports neverCalled;
  347. };
  348.  
  349. /***************************************************************************/
  350.  
  351. /*
  352.  * This interface is implemented by outside code and registered with xpconnect
  353.  * via nsIXPConnect::setFunctionThisTranslator.
  354.  *
  355.  * The reason this exists is to support calls to JavaScript event callbacks
  356.  * needed by the DOM via xpconnect from C++ code.
  357.  *
  358.  * We've added support for wrapping JS function objects as xpcom interfaces
  359.  * by declaring the given interface as a [function] interface. However, to
  360.  * support the requirements of JS event callbacks we need to call the JS
  361.  * function with the 'this' set as the JSObject for which the event is being
  362.  * fired; e.g. a form node.
  363.  *
  364.  * We've decided that for all cases we care about the appropriate 'this' object
  365.  * can be derived from the first param in the call to the callback. In the
  366.  * event handler case the first param is an event object.
  367.  *
  368.  * Though we can't change all the JS code so that it would setup its own 'this',
  369.  * we can add plugin 'helper' support to xpconnect. And that is what we have
  370.  * here.
  371.  *
  372.  * The idea is that at startup time some code that cares about this issue
  373.  * (e.g. the DOM helper code) can register a nsIXPCFunctionThisTranslator
  374.  * object with xpconnect to handle calls to [function] interfaces of a given
  375.  * iid. When xpconnect goes to invoke a method on a wrapped JSObject for
  376.  * an interface marked as [function], xpconnect will check if the first param
  377.  * of the method is an xpcom object pointer and if so it will check to see if a
  378.  * nsIXPCFunctionThisTranslator has been registered for the given iid of the
  379.  * interface being called. If so it will call the translator and get an
  380.  * interface pointer to use as the 'this' for the call. If the translator
  381.  * returns a non-null interface pointer (which it should then have addref'd
  382.  * since it is being returned as an out param), xpconnect will attempt to build
  383.  * a wrapper around the pointer and get a JSObject from that wrapper to use
  384.  * as the 'this' for the call.
  385.  *
  386.  * If a null interface pointer is returned then xpconnect will use the default
  387.  * 'this' - the same JSObject as the function object it is calling.
  388.  *
  389.  * The translator can also return a non-null aIIDOfResult to tell xpconnect what
  390.  * type of wrapper to build. If that is null then xpconnect will assume the
  391.  * wrapper should be for nsISupports. For objects that support flattening -
  392.  * i.e. expose nsIClassInfo and that interface's getInterfaces method - then
  393.  * a flattened wrapper will be created and no iid was really necessary.
  394.  *
  395.  * XXX aHideFirstParamFromJS is intended to allow the trimming of that first
  396.  * param (used to indicate 'this') from the actual call to the JS code. The JS
  397.  * DOM does not require this functionality and it is **NOT YET IMPLEMENTED**
  398.  *
  399.  */
  400.  
  401. [scriptable, uuid(039ef260-2a0d-11d5-90a7-0010a4e73d9a)]
  402. interface nsIXPCFunctionThisTranslator : nsISupports
  403. {
  404.     nsISupports TranslateThis(in nsISupports        aInitialThis,
  405.                               in nsIInterfaceInfo   aInterfaceInfo,
  406.                               in PRUint16           aMethodIndex,
  407.                               out PRBool            aHideFirstParamFromJS,
  408.                               out nsIIDPtr          aIIDOfResult);
  409. };
  410.  
  411. /***************************************************************************/
  412.  
  413. %{ C++
  414. // For use with the service manager
  415. // {CB6593E0-F9B2-11d2-BDD6-000064657374}
  416. #define NS_XPCONNECT_CID \
  417. { 0xcb6593e0, 0xf9b2, 0x11d2, \
  418.     { 0xbd, 0xd6, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
  419. %}
  420.  
  421. [uuid(DEB1D48E-7469-4B01-B186-D9854C7D3F2D)]
  422. interface nsIXPConnect : nsISupports
  423. {
  424. %{ C++
  425.   NS_DEFINE_STATIC_CID_ACCESSOR(NS_XPCONNECT_CID)
  426. %}
  427.  
  428.     void
  429.     initClasses(in JSContextPtr aJSContext,
  430.                 in JSObjectPtr  aGlobalJSObj);
  431.  
  432.     nsIXPConnectJSObjectHolder
  433.     initClassesWithNewWrappedGlobal(
  434.                   in JSContextPtr aJSContext,
  435.                   in nsISupports  aCOMObj,
  436.                   in nsIIDRef     aIID,
  437.                   in PRUint32     aFlags);
  438.  
  439.     const PRUint32 INIT_JS_STANDARD_CLASSES  = 1 << 0;
  440.     const PRUint32 FLAG_SYSTEM_GLOBAL_OBJECT = 1 << 1;
  441.  
  442.     /**
  443.     * wrapNative will create a new JSObject or return an existing one.
  444.     *
  445.     * The JSObject is returned inside a refcounted nsIXPConnectJSObjectHolder.
  446.     * As long as this holder is held the JSObject will be protected from
  447.     * collection by JavaScript's garbage collector. It is a good idea to
  448.     * transfer the JSObject to some equally protected place before releasing
  449.     * the holder (i.e. use JS_SetProperty to make this object a property of
  450.     * some other JSObject).
  451.     *
  452.     * This method now correctly deals with cases where the passed in xpcom
  453.     * object already has an associated JSObject for the cases:
  454.     *  1) The xpcom object has already been wrapped for use in the same scope
  455.     *     as an nsIXPConnectWrappedNative.
  456.     *  2) The xpcom object is in fact a nsIXPConnectWrappedJS and thus already
  457.     *     has an underlying JSObject.
  458.     *  3) The xpcom object implements nsIScriptObjectOwner; i.e. is an idlc
  459.     *     style DOM object for which we can call GetScriptObject to get the
  460.     *     JSObject it uses to represent itself into JavaScript.
  461.     *
  462.     * It *might* be possible to QueryInterface the nsIXPConnectJSObjectHolder
  463.     * returned by the method into a nsIXPConnectWrappedNative or a
  464.     * nsIXPConnectWrappedJS.
  465.     *
  466.     * This method will never wrap the JSObject involved in an
  467.     * XPCNativeWrapper before returning.
  468.     *
  469.     * Returns:
  470.     *    success:
  471.     *       NS_OK
  472.     *    failure:
  473.     *       NS_ERROR_XPC_BAD_CONVERT_NATIVE
  474.     *       NS_ERROR_XPC_CANT_GET_JSOBJECT_OF_DOM_OBJECT
  475.     *       NS_ERROR_FAILURE
  476.     */
  477.     nsIXPConnectJSObjectHolder
  478.     wrapNative(in JSContextPtr aJSContext,
  479.                in JSObjectPtr  aScope,
  480.                in nsISupports  aCOMObj,
  481.                in nsIIDRef     aIID);
  482.  
  483.     /**
  484.     * wrapJS will yield a new or previously existing xpcom interface pointer
  485.     * to represent the JSObject passed in.
  486.     *
  487.     * This method now correctly deals with cases where the passed in JSObject
  488.     * already has an associated xpcom interface for the cases:
  489.     *  1) The JSObject has already been wrapped as a nsIXPConnectWrappedJS.
  490.     *  2) The JSObject is in fact a nsIXPConnectWrappedNative and thus already
  491.     *     has an underlying xpcom object.
  492.     *  3) The JSObject is of a jsclass which supports getting the nsISupports
  493.     *     from the JSObject directly. This is used for idlc style objects
  494.     *     (e.g. DOM objects).
  495.     *
  496.     * It *might* be possible to QueryInterface the resulting interface pointer
  497.     * to nsIXPConnectWrappedJS.
  498.     *
  499.     * Returns:
  500.     *   success:
  501.     *     NS_OK
  502.     *    failure:
  503.     *       NS_ERROR_XPC_BAD_CONVERT_JS
  504.     *       NS_ERROR_FAILURE
  505.     */
  506.     void
  507.     wrapJS(in JSContextPtr aJSContext,
  508.            in JSObjectPtr  aJSObj,
  509.            in nsIIDRef     aIID,
  510.            [iid_is(aIID),retval] out nsQIResult result);
  511.  
  512.     /**
  513.     * This only succeeds if the JSObject is a nsIXPConnectWrappedNative.
  514.     * A new wrapper is *never* constructed.
  515.     */
  516.     nsIXPConnectWrappedNative
  517.     getWrappedNativeOfJSObject(in JSContextPtr aJSContext,
  518.                                in JSObjectPtr  aJSObj);
  519.  
  520.     void setSecurityManagerForJSContext(in JSContextPtr aJSContext,
  521.                                         in nsIXPCSecurityManager aManager,
  522.                                         in PRUint16 flags);
  523.  
  524.     void getSecurityManagerForJSContext(in JSContextPtr aJSContext,
  525.                                         out nsIXPCSecurityManager aManager,
  526.                                         out PRUint16 flags);
  527.  
  528.     /**
  529.     * The security manager to use when the current JSContext has no security
  530.     * manager.
  531.     */
  532.     void setDefaultSecurityManager(in nsIXPCSecurityManager aManager,
  533.                                    in PRUint16 flags);
  534.  
  535.     void getDefaultSecurityManager(out nsIXPCSecurityManager aManager,
  536.                                    out PRUint16 flags);
  537.  
  538.     nsIStackFrame
  539.     createStackFrameLocation(in PRUint32       aLanguage,
  540.                              in string         aFilename,
  541.                              in string         aFunctionName,
  542.                              in PRInt32        aLineNumber,
  543.                              in nsIStackFrame  aCaller);
  544.  
  545.     /**
  546.     * XPConnect builds internal objects that parallel, and are one-to-one with,
  547.     * the JSContexts in the JSRuntime. It builds these objects as needed.
  548.     * This method tells XPConnect to resynchronize its representations with the
  549.     * list of JSContexts currently 'alive' in the JSRuntime. This allows it
  550.     * to cleanup any representations of JSContexts that are no longer valid.
  551.     */
  552.     void syncJSContexts();
  553.  
  554.     readonly attribute nsIStackFrame                CurrentJSStack;
  555.     readonly attribute nsIXPCNativeCallContext      CurrentNativeCallContext;
  556.     /* pass nsnull to clear pending exception */
  557.              attribute nsIException                 PendingException;
  558.  
  559.     void debugDump(in short depth);
  560.     void debugDumpObject(in nsISupports aCOMObj, in short depth);
  561.     void debugDumpJSStack(in PRBool showArgs,
  562.                           in PRBool showLocals,
  563.                           in PRBool showThisProps);
  564.     void debugDumpEvalInJSStackFrame(in PRUint32 aFrameNumber,
  565.                                      in string aSourceText);
  566.  
  567.     /**
  568.     * Set fallback JSContext to use when xpconnect can't find an appropriate
  569.     * context to use to execute JavaScript.
  570.     *
  571.     * NOTE: This method is DEPRECATED. 
  572.     *       Use nsIThreadJSContextStack::safeJSContext instead.
  573.     */
  574.     void setSafeJSContextForCurrentThread(in JSContextPtr cx);
  575.  
  576.     /**
  577.     * wrapJSAggregatedToNative is just like wrapJS except it is used in cases
  578.     * where the JSObject is also aggregated to some native xpcom Object.
  579.     * At present XBL is the only system that might want to do this.
  580.     *
  581.     * XXX write more!
  582.     *
  583.     * Returns:
  584.     *   success:
  585.     *     NS_OK
  586.     *    failure:
  587.     *       NS_ERROR_XPC_BAD_CONVERT_JS
  588.     *       NS_ERROR_FAILURE
  589.     */
  590.     void
  591.     wrapJSAggregatedToNative(in nsISupports  aOuter,
  592.                              in JSContextPtr aJSContext,
  593.                              in JSObjectPtr  aJSObj,
  594.                              in nsIIDRef     aIID,
  595.                              [iid_is(aIID),retval] out nsQIResult result);
  596.  
  597.     // Methods added since mozilla 0.6....
  598.  
  599.     /**
  600.     * This only succeeds if the native object is already wrapped by xpconnect.
  601.     * A new wrapper is *never* constructed.
  602.     */
  603.     nsIXPConnectWrappedNative
  604.     getWrappedNativeOfNativeObject(in JSContextPtr aJSContext,
  605.                                    in JSObjectPtr  aScope,
  606.                                    in nsISupports  aCOMObj,
  607.                                    in nsIIDRef     aIID);
  608.  
  609.     nsIXPCFunctionThisTranslator
  610.     getFunctionThisTranslator(in nsIIDRef aIID);
  611.  
  612.     nsIXPCFunctionThisTranslator
  613.     setFunctionThisTranslator(in nsIIDRef aIID,
  614.                               in nsIXPCFunctionThisTranslator aTranslator);
  615.  
  616.     nsIXPConnectJSObjectHolder
  617.     reparentWrappedNativeIfFound(in JSContextPtr aJSContext,
  618.                                  in JSObjectPtr  aScope,
  619.                                  in JSObjectPtr  aNewParent,
  620.                                  in nsISupports  aCOMObj);
  621.  
  622.     void clearAllWrappedNativeSecurityPolicies();
  623.  
  624.     nsIXPConnectJSObjectHolder
  625.     getWrappedNativePrototype(in JSContextPtr aJSContext,
  626.                               in JSObjectPtr  aScope,
  627.                               in nsIClassInfo aClassInfo);
  628.  
  629.     attribute PRBool collectGarbageOnMainThreadOnly;
  630.     attribute PRBool deferReleasesUntilAfterGarbageCollection;
  631.  
  632.     void releaseJSContext(in JSContextPtr aJSContext, in PRBool noGC);
  633.  
  634.     JSVal variantToJS(in JSContextPtr ctx, in JSObjectPtr scope, in nsIVariant value);
  635.     nsIVariant JSToVariant(in JSContextPtr ctx, in JSVal value);
  636.  
  637.     /**
  638.      * Preconfigure XPCNativeWrapper automation so that when a scripted
  639.      * caller whose filename starts with filenamePrefix accesses a wrapped
  640.      * native that is not flagged as "system", the wrapped native will be
  641.      * automatically wrapped with an XPCNativeWrapper.
  642.      *
  643.      * @param aFilenamePrefix the UTF-8 filename prefix to match, which
  644.      *                        should end with a slash (/) character
  645.      */
  646.     void flagSystemFilenamePrefix(in string aFilenamePrefix);
  647.  
  648.     /**
  649.      * Restore an old prototype for wrapped natives of type
  650.      * aClassInfo. This should be used only when restoring an old
  651.      * scope into a state close to where it was prior to
  652.      * being reinitialized.
  653.      */
  654.     void restoreWrappedNativePrototype(in JSContextPtr aJSContext,
  655.                                        in JSObjectPtr  aScope,
  656.                                        in nsIClassInfo aClassInfo,
  657.                                        in nsIXPConnectJSObjectHolder aPrototype);
  658. };
  659.